<template>
	<view class="page_bg">
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<!-- #endif -->
		<view class="top_nav">
			<image src="/static/local/3546451940011a031009b939a8b26314.png" class="image_1" @click="pageBack" />
			<view class="cate">会员专享</view>
		</view>
		<view class="flex-col group_1">
			<view class="flex-row section_1" @tap="popShow = true">
				<image src="/static/local/3aa07251028c2ee9d409337d259cb3f9.png" class="image_2" />
				<view class="text_1">{{nowCourseName || '未选择'}}</view>
			</view>
			<view class="flex-col group_2">
				<view class="grid">
					<view class="grid-item flex-row" @tap="JumpToChapters">
						<view class="flex-col group_3">
							<text class="text_2">章节练习</text>
							<text class="text_4">针对训练，重点掌握</text>
						</view>
						<image src="/static/local/16403089502724267483.png" class="image_3" />
					</view>
					<view class="grid-item flex-row" @tap="JumpToCenter('核心知识点')">
						<view class="flex-col group_4">
							<text class="text_2">核心知识点</text>
							<text class="text_4">专业解析，知识难点</text>
						</view>
						<image src="/static/local/16403089502735192479.png" class="image_4 image_5" />
					</view>
					<view class="grid-item justify-between" @tap="JumpToCenter('考前分析')">
						<view class="flex-col">
							<text class="text_2">考前分析</text>
							<text class="text_4">考前开放</text>
						</view>
						<image src="/static/local/16403089502736923482.png" class="image_4 image_6" />
					</view>
				</view>
				<u-modal v-model="show" :show-title="false" content="购买相应课程后可获得此题库权限~"></u-modal>
			</view>
		</view>
		<u-popup v-model="popShow" mode="bottom" height="70%" :closeable="true">
			<view class="pop_bg">
				<view class="title">选择课程</view>
				<scroll-view scroll-y class="main">
					<view class="course_item" v-for="item in courseList" :key="item._id"
						@tap="selectCourse(item.courseInfo)">
						<u-image :src="item.courseInfo.thumb" :lazy-load="true" class="image_12" mode="aspectFill">
						</u-image>
						<view class="item_title">{{item.courseInfo.title}}</view>
					</view>
				</scroll-view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk; // vk依赖
	export default {
		data() {
			// 页面数据变量
			return {
				// 分类id
				cid: '',
				// 已购课程列表
				courseList: [],
				// 当前选中课程
				nowCourseId: '',
				nowCourseName: '',

				popShow: false,
				show: false
			}
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.init(options)
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options) {
				this.cid = options.cateId
				this.getMyCourse()
			},
			pageBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 获取所有已购课程
			getMyCourse() {
				vk.callFunction({
					url: 'client/quest-bank/kh/vip/getMyCourseList',
					title: '获取课程中...',
					data: { need_user_info: true },
					success(data) {
						that.courseList = data.rows
						// 默认显示分类所选课程
						data.rows.map(v => {
							if (v.courseInfo.category_id == that.cid) {
								that.nowCourseId = v.courseInfo._id
								that.nowCourseName = v.courseInfo.title
							}
						})
					}
				});
			},
			// 选择完成
			selectCourse(info) {
				this.popShow = false
				this.$nextTick(() => {
					this.nowCourseId = info._id
					this.nowCourseName = info.title
				})
			},
			// 所有权检测
			canJump() {
				this.show = true
				return true
			},
			// 跳转章节
			JumpToChapters() {
				uni.navigateTo({
					url: `/pages/question-bank/vip-chapter-page?cid=${that.nowCourseId}`
				})
			},
			// 跳转核心知识点或考前分析
			JumpToCenter(title) {
				uni.navigateTo({
					url: `/pages/question-bank/vip-rich-page?title=${title}&cid=${that.nowCourseId}`
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.page_bg {
		background-color: #F5F5F5;
		width: 100%;
		height: 100vh;
		overflow-y: auto;

		.status_bar,
		.top_view {
			background-color: #FDD303;
		}

		.top_nav {
			padding-bottom: 24rpx;
			color: rgb(51, 51, 51);
			font-size: 34rpx;
			line-height: 41rpx;
			white-space: nowrap;
			background: linear-gradient(179deg, #FDD303 0%, #FFAC05 100%);
			height: 90rpx;
			position: relative;

			.image_1 {
				left: 21rpx;
				top: 27rpx;
				width: 19rpx;
				height: 35rpx;
				position: absolute;
			}

			.cate {
				width: 100%;
				padding: 20rpx 0;
				color: rgb(51, 51, 51);
				font-size: 34rpx;
				font-weight: 500;
				line-height: 41rpx;
				white-space: nowrap;
				text-align: center;
			}
		}

		.group_1 {
			flex: 1 1 auto;
			overflow-y: auto;

			.section_1 {
				padding: 36rpx 20rpx;
				color: rgb(51, 51, 51);
				font-size: 32rpx;
				line-height: 41rpx;
				white-space: nowrap;
				background-color: rgb(255, 255, 255);

				.image_2 {
					margin: 10rpx 0;
					width: 20rpx;
					height: 20rpx;
				}

				.text_1 {
					margin-left: 14rpx;
					flex: 1;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}

			.group_2 {
				margin-top: 20rpx;
				padding: 0 20rpx;

				.grid {
					height: 344rpx;
					display: grid;
					grid-template-columns: repeat(2, 1fr);
					grid-row-gap: 22rpx;
					grid-column-gap: 24rpx;

					.grid-item {
						padding: 40rpx 20rpx 38rpx;
						background-color: rgb(255, 255, 255);
						border-radius: 12rpx;

						.group_3 {
							flex: 1 1 auto;
						}

						.image_3 {
							margin: 8rpx 0 10rpx 17rpx;
							width: 64rpx;
							height: 66rpx;
						}

						.group_4 {
							flex: 1 1 auto;
						}

						.image_4 {
							align-self: center;
							width: 61rpx;
							height: 63rpx;
						}

						.image_5 {
							margin-left: 19rpx;
							margin-right: 3rpx;
						}

						.image_6 {
							margin-right: 3rpx;
						}

						.text_2 {
							color: rgb(51, 51, 51);
							font-size: 30rpx;
							line-height: 36rpx;
							white-space: nowrap;
						}

						.text_4 {
							margin-top: 20rpx;
							color: rgb(153, 153, 153);
							font-size: 24rpx;
							line-height: 29rpx;
							white-space: nowrap;
						}
					}
				}
			}
		}
	}

	.pop_bg {
		padding: 30rpx;
		box-sizing: border-box;
		height: 100%;

		.title {
			text-align: center;
			font-size: 30rpx;
			font-weight: bold;
		}

		.main {
			height: calc(100% - 50rpx);
			margin-top: 10rpx;

			.course_item {
				padding: 40rpx 0;
				border-bottom: 2rpx solid #F0F0F0;
				display: flex;

				.image_12 {
					width: 230rpx !important;
					height: 120rpx !important;
					border-radius: 8rpx !important;
					overflow: hidden !important;
					margin-right: 20rpx;
				}

				.item_title {
					flex: 1;
					word-break: break-all;
					text-overflow: ellipsis;
					overflow: hidden;
					display: -webkit-box;
					-webkit-line-clamp: 3;
					-webkit-box-orient: vertical;
				}
			}
		}
	}
</style>
